﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Resn.WhuPub.DML;

namespace Resn.WhuPub.BLL
{
        public class GlobalManager : NotifyPropertyChangedObject
        {
                #region 构造函数

                private GlobalManager()
                {
                        CorporateEntityManager = new EntityManager<Corporate, CorporateModel>();
                        BranchEntityManager = new EntityManager<Branch, BranchModel>();
                        DepartmentEntityManager = new EntityManager<Department, DepartmentModel>();

                        MajorSetupEntityManager = new EntityManager<MajorSetup, MajorSetupModel>();
                        MajorOperationEntityManager = new EntityManager<MajorOperation, MajorOperationModel>();

                        ContactEntityManager = new EntityManager<Contact, ContactModel>();
                        BookEntityManager = new EntityManager<Book, BookModel>();
                        BookFlowEntityManager = new EntityManager<BookFlow, BookFlowModel>();

                        CategoryEntityManager = new EntityManager<Category, CategoryModel>();
                        SubjectEntityManager = new EntityManager<Subject, SubjectModel>();
                        MajorEntityManager = new EntityManager<Major, MajorModel>();

                        DealerEntityManager = new EntityManager<Dealer, DealerModel>();
                        InvoiceFlowEntityManager = new EntityManager<InvoiceFlow, InvoiceFlowModel>();


                        EmployeeEntityManager = new EntityManager<Employee, EmployeeModel>();

                        TravelFlowEntityManager = new EntityManager<TravelFlow, TravelFlowModel>();


                        VisitEntityManager = new EntityManager<Visit, VisitModel>();
                }

                #endregion

                #region 属性

                private static GlobalManager _instance;

                /// <summary>
                ///         获取机车管理器实例
                /// </summary>
                /// <value>
                ///         机车管理器实例
                /// </value>
                public static GlobalManager Instance
                {
                        get { return _instance ?? (_instance = new GlobalManager()); }
                }

                #region 新建

                public string Name { get; set; }

                public string Title { get; set; }

                public string Duty { get; set; }

                public String SoicalDuty { get; set; }

                public string Telephone { get; set; }

                public string QQ { get; set; }

                public string Email { get; set; }

                public String Address { get; set; }

                public String Postcode { get; set; }

                public String Website { get; set; }

                public string Memo { get; set; }

                public string Code { get; set; }

                public string ProvinceString { get; set; }

                public string CityString { get; set; }


                public bool IsOwnAuthor { get; set; }


                public DateTime StartTime { get; set; }

                public DateTime EndTime { get; set; }

                public DateTime EnteringTime { get; set; }




                public List<CorporateLevel> CorporateLevels
                {
                        get { return typeof(CorporateLevel).GetEnums<CorporateLevel>(); }
                }

                public CorporateLevel CorporateLevel { get; set; }


                public EmployeeLevel EmployeeLevel { get; set; }

                public List<EmployeeState> EmployeeStates
                {
                        get { return typeof(EmployeeState).GetEnums<EmployeeState>(); }
                }

                public EmployeeState EmployeeState { get; set; }


                public CategoryLevel CategoryLevel { get; set; }

                #endregion

                #region 省

                public EntityManager<Province, ProvinceModel> ProvinceEntityManager { get; private set; }

                private ObservableCollection<Province> _provinces;

                public ObservableCollection<Province> Provinces
                {
                        get
                        {
                                if (_provinces == null)
                                {
                                        _provinces = new ObservableCollection<Province>(Province.Provinces);
                                }
                                return _provinces;
                        }
                }

                private Province _province;

                public Province Province
                {
                        get { return _province; }
                        set
                        {
                                _province = value;
                                this.NotifyPropertyChanged(i => i.Province);

                                Citys = _province.Citys;
                        }
                }

                #endregion

                #region 市

                public EntityManager<City, CityModel> CityEntityManager { get; private set; }

                private ObservableCollection<City> _citys;

                public ObservableCollection<City> Citys
                {
                        get { return _citys; }
                        private set
                        {
                                _citys = value;
                                this.NotifyPropertyChanged(i => i.Citys);

                                City = Citys.First();
                        }
                }

                private City _city;

                public City City
                {
                        get { return _city; }
                        set
                        {
                                _city = value;
                                this.NotifyPropertyChanged(i => i.City);
                        }
                }

                #endregion

                #region 门类

                public EntityManager<Category, CategoryModel> CategoryEntityManager { get; private set; }

                private ObservableCollection<Category> categorys;

                public ObservableCollection<Category> Categorys
                {
                        get { return categorys; }
                        set
                        {
                                categorys = value;
                                this.NotifyPropertyChanged(i => i.Categorys);

                                Category = categorys.FirstOrDefault();
                        }
                }

                private Category _category;

                public Category Category
                {
                        get { return _category; }
                        set
                        {
                                _category = value;
                                this.NotifyPropertyChanged(i => i.Category);

                                if (_category != null)
                                {
                                        Subjects = _category.Subjects;
                                }
                        }
                }
                

                #endregion

                #region 科目

                public EntityManager<Subject, SubjectModel> SubjectEntityManager { get; private set; }

                private ObservableCollection<Subject> _subjects;

                public ObservableCollection<Subject> Subjects
                {
                        get { return _subjects; }
                        set
                        {
                                _subjects = value;
                                this.NotifyPropertyChanged(i => i.Subjects);
                                Subject = _subjects.FirstOrDefault();
                        }
                }

                private Subject _subject;

                public Subject Subject
                {
                        get { return _subject; }
                        set
                        {
                                _subject = value;
                                this.NotifyPropertyChanged(i => i.Subject);

                                if (Subject != null)
                                {
                                        Majors = _subject.Majors;
                                }
                        }
                }

                #endregion

                #region 专业

                public EntityManager<Major, MajorModel> MajorEntityManager { get; private set; }

                

                private ObservableCollection<Major> _majors;

                public ObservableCollection<Major> Majors
                {
                        get { return _majors; }
                        set
                        {
                                _majors = value;
                                this.NotifyPropertyChanged(i => i.Majors);

                                Major = _majors.FirstOrDefault();
                        }
                }

                private Major _major;


                public Major Major
                {
                        get { return _major; }
                        set
                        {
                                _major = value;
                                this.NotifyPropertyChanged(i => i.Major);
                        }
                }

                #endregion

                #region 学校

                public EntityManager<Corporate, CorporateModel> CorporateEntityManager { get; private set; }

                private ObservableCollection<Corporate> _corporates;

                public ObservableCollection<Corporate> Corporates
                {
                        get { return _corporates; }
                        set
                        {
                                _corporates = value;
                                this.NotifyPropertyChanged(i => i.Corporates);
                        }
                }

                private Corporate _corporate;

                public Corporate Corporate
                {
                        get { return _corporate; }
                        set
                        {
                                _corporate = value;
                                this.NotifyPropertyChanged(i => i.Corporate);
                        }
                }

                


                #endregion

                #region 校区

                public EntityManager<Branch, BranchModel> BranchEntityManager { get; private set; }

                public ObservableCollection<Branch> Branchs { get; set; }

                public Branch Branch { get; set; }

                #endregion

                #region 部门

                public EntityManager<Department, DepartmentModel> DepartmentEntityManager { get; private set; }

                public ObservableCollection<Department> Departments { get; set; }

                public Department Department { get; set; }

                #endregion

                #region 联系人

                public EntityManager<Contact, ContactModel> ContactEntityManager { get; private set; }

                public ObservableCollection<Contact> Contacts { get; set; }

                public Contact Contact { get; set; }

                #endregion

                #region 反馈

                public EntityManager<FeedbackFlow, FeedbackFlowModel> FeedbackFlowEntityManager { get; private set; }

                public ObservableCollection<FeedbackFlow> FeedbackFlows { get; set; }

                public FeedbackFlow FeedbackFlow { get; set; }

                #endregion

                #region 书籍

                public EntityManager<Book, BookModel> BookEntityManager { get; private set; }

                public ObservableCollection<Book> Books { get; set; }

                public Book Book { get; set; }

                #endregion

                #region 样书寄送

                public EntityManager<BookFlow, BookFlowModel> BookFlowEntityManager { get; private set; }

                public ObservableCollection<BookFlow> BookFlows { get; set; }

                public BookFlow BookFlow { get; set; }

                #endregion

                #region 经销商

                public EntityManager<Dealer, DealerModel> DealerEntityManager { get; private set; }

                public ObservableCollection<Dealer> Dealers { get; set; }

                public Dealer Dealer { get; set; }

                #endregion

                #region 发票寄送流程

                public EntityManager<InvoiceFlow, InvoiceFlowModel> InvoiceFlowEntityManager { get; private set; }

                public ObservableCollection<InvoiceFlow> InvoiceFlows { get; set; }

                public InvoiceFlow InvoiceFlow { get; set; }

                #endregion

                #region 专业开设

                public EntityManager<MajorSetup, MajorSetupModel> MajorSetupEntityManager { get; private set; }

                public ObservableCollection<MajorSetup> MajorSetups { get; set; }

                public MajorSetup MajorSetup { get; set; }

                

                

                

                public string MajorSetupManagerName { get; set; }

                public string MajorSetupTeachingManagerName { get; set; }

                #endregion

                #region 专业招生

                public EntityManager<MajorOperation, MajorOperationModel> MajorOperationEntityManager { get; private set; }

                public List<MajorOperation> MajorOperations { get; set; }

                public MajorOperation MajorOperation { get; set; }

                public List<int> MajorOperationYears
                {
                        get
                        {
                                var result = new List<int>();
                                for (int i = 2000; i < 2030; i++)
                                {
                                        result.Add(i);
                                }
                                return result;
                        }
                }

                public int MajorOperationYear { get; set; }


                public List<int> MajorOperationStudentsAmounts
                {
                        get
                        {
                                var result = new List<int>();
                                for (int i = 1; i < 121; i++)
                                {
                                        result.Add(i);
                                }
                                return result;
                        }
                }

                public int MajorOperationStudentsAmount { get; set; }

                #endregion

                #region 课程

                public EntityManager<Course, CourseModel> CourseEntityManager { get; private set; }

                public ObservableCollection<Course> Courses { get; set; }

                public Course Course { get; set; }

                public string CourseName { get; set; }

                public string CourseCode { get; set; }

                public string CourseLevel { get; set; }

                #endregion

                #region 课本

                public CourseBook CourseBook { get; set; }

                #endregion

                

                #region 用户

                public EntityManager<Employee, EmployeeModel> EmployeeEntityManager { get; private set; }


                public ObservableCollection<Employee> Employees { get; set; }

                public Employee Employee { get; set; }



                public Employee LoginEmployee { get; set; }

                public List<Employee> NormalEmployees
                {
                        get { return EmployeeEntityManager.Entitys.Where(i => i.Level == EmployeeLevel.普通用户).ToList(); }
                }

                public Employee ApproveEmployee { get; set; }

                public Province EmployeeProvince { get; set; }


                public int AdministratorsCount
                {
                        get { return EmployeeEntityManager.Entitys.Count(i => i.Level == EmployeeLevel.管理员); }
                }

                public int UsersCount
                {
                        get
                        {
                                return
                                        EmployeeEntityManager.Entitys.Count(i => i.Level == EmployeeLevel.普通用户);
                        }
                }

                #endregion

                #region 差旅

                public EntityManager<TravelFlow, TravelFlowModel> TravelFlowEntityManager { get; private set; }

                private ObservableCollection<TravelFlow> _travelFlows;

                public ObservableCollection<TravelFlow> TravelFlows
                {
                        get { return _travelFlows; }
                        set
                        {
                                _travelFlows = value;
                                this.NotifyPropertyChanged(i => i.TravelFlows);
                        }
                }

                public TravelFlow TravelFlow { get; set; }

                public string TravelFlowPlanContent { get; set; }

                public string TravelFlowPlanModify { get; set; }

                public Double TravelFlowLendAmount { get; set; }

                #endregion

                #region 拜访

                public EntityManager<Visit, VisitModel> VisitEntityManager { get; private set; }

                public ObservableCollection<Visit> Visits { get; set; }

                public Visit Visit { get; set; }

                public Contact VisitContact { get; set; }

                public VisitType VisitVisitType { get; set; }

                public string VisitObjective { get; set; }

                public string VisitKeyEvents { get; set; }

                public Double VisitEatAmount { get; set; }

                public Double VisitGiftAmount { get; set; }

                #endregion

                #endregion
        }
}